package controller.users;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.*;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LoginForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String name = null;
	private String pass = null;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPass() {
		return pass;
	}
	public void setPass(String pass) {
		this.pass = pass;
	}
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		  this.pass = null;
		  this.name = null;
		}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		  ActionErrors errors = new ActionErrors();

		  if ((name == null) || (name.length() == 0))
		    errors.add("name", new ActionMessage("erreur.name.obligatoire"));

		  if ((pass == null) || (pass.length() == 0))
		    errors.add("pass", new ActionMessage("erreur.pass.obligatoire"));

		  return errors;
		}
}
